package com.hkx;

import com.hkx.domain.User;
import com.hkx.service.IUserService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

/**
 * 用户的业务层测试
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class test {

    @Autowired
    private IUserService userService;

    @Test
    public void testFindAll(){

        List<User> all = userService.findAll();
        for (User user : all){
            System.out.println(user);
        }
    }

    @Test
    public void testFindOne(){

        User user = userService.findById(1);
        System.out.println(user);
    }

    @Test
    public void testUpdate(){
        User user = userService.findById(1);
        System.out.println("修改前的用户"+user);
        user.setAge(11);
        user.setUsername("张三");
        user.setSex("男");
        userService.updateUser(user);
        userService.findById(1);
        System.out.println("修改后"+user);

    }
}
